/**
 * 首屏
 *
 * @author li.youxi
 * @date 2017/05/25
 */

import './index.scss';
import tpl from './index.html';
import globalMessage from 'libs/globalMessage.js';
import {IScroll} from 'js/libs/iscroll-probe';
import bugObj from './demo/bug/index.js';
import yejiObj from './demo/yeji/index.js';
import lookObj from './demo/lookme/index.js';
import planObj from './demo/plan/index.js';

let doc = document;

let mainObj = {
    // init: function(type){
    //     type = type || 'bug';
    //     manager(() => {
    //         doc.querySelector('#game_main').innerHTML = tpl;
    //     });
    //     // .then(() => {
    //     //     this.setPage(type);
    //     // });
        
    //     this.bindEvent();
    // },

    setPage (type) {
        manager(() => {
            switch(type) {
                case 'yeji':
                    yejiObj.init();
                    break;
                case 'bug':
                    bugObj.init();
                    break;
                case 'look':
                    lookObj.init();
                    break;
                case 'plan':
                    planObj.init();
                    break;
                
            }
        }, 300).then(() => {
            new IScroll('#game_main', { probeType: 3,mouseWheel: true, click: false });
        });
        
    },

    bindEvent: function(){
        
    }
};

function manager (cb, time) {
    return new Promise((resolve, reject) => {
        if (cb && typeof cb === 'function') {
            cb();
        }

        if (time) {
            setTimeout(() => {
                return resolve();
            }, time);
        } else {
            requestAnimationFrame(() => {
                return resolve();
            });
        }
        
    });
}

export default mainObj;